package com.yanqu.road.server.cmd.activity.hanghai.cross;

import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.pb.activity.HangHaiActivityProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.hanghai.HangHaiModule;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.gameplayer.module.player.PreReduceModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.property.PropertyHelper;

@Cmd(code = GameProtocol.S_HANGHAI_ACTIVITY_UPGRADE_SHIP_FROM_CROSS, desc = "（跨服返回）返回升级船")
public class HangHaiUpgradeShipFromCrossCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        HangHaiActivityProto.CrossHangHaiUpgradeShipRespMsg respMsg = HangHaiActivityProto.CrossHangHaiUpgradeShipRespMsg.parseFrom(packet.getBytes());
        HangHaiActivityProto.HangHaiUpgradeShipRespMsg resp = respMsg.getResp();
        String preReduceCost = respMsg.getPreReduceCost();

        if (!"0".equals(preReduceCost)) {
            player.getModule(PreReduceModule.class).restorePreReduce(preReduceCost);
        }
        player.getModule(HangHaiModule.class).setUpdateShipReqTime(0L);

        if (resp.getRet() == 0) {
            player.getModule(CurrencyModule.class).removeCurrency(PropertyHelper.parseStringToProperty(preReduceCost), eLogMoneyType.HangHaiActivity, eLogMoneyType.HangHaiUpgradeShipCost);
        }

        player.sendPacket(ClientProtocol.U_HANGHAI_ACTIVITY_UPGRADE_SHIP, resp.toBuilder());
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
